package com.efounder.util;

import android.content.Context;

import com.efounder.mobilemanager.R;
import com.utilcode.util.FileUtils;

import java.lang.reflect.Field;

/**
 * 检查package 文件夹中的文件是否存在，不存在，则需要下载资源文件
 * Created by YQS on 2017/11/29.
 * @see BeforeLoginCheckUtils
 */
@Deprecated

public class PackgeFileCheckUtil {
    /**
     * 检查配置文件是否完整
     */
    public static boolean checkFileIsFull(Context context) {
        boolean isFull = true;
        Class clazz = null;
        String fileDir = null;
        try {
            clazz = Class.forName("com.efounder.chat.model.Constant");
            Field field = clazz.getField("appSdcardLocation");
            fileDir = (String) field.get(clazz);
        } catch (Exception e) {
            e.printStackTrace();
            return true;
        }

        //数组中配置的是需要的xml文件，如果需要更多，主工程可以覆盖这个数组
        String[] array = context.getApplicationContext().getResources().getStringArray(R.array.menuRootFile);
        if (array == null) {
            return true;
        }
        for (int i = 0; i < array.length; i++) {
            String fileName = array[i];
            String filePath = fileDir + "/" + fileName;

            boolean exist = FileUtils.isFileExists(filePath);
            if (!exist) {
                isFull = false;
                break;
            }
        }

        return isFull;
    }
}
